//
//  UIButton+ZKChain.m
//  ChainFun
//
//  Created by 洪绵卫 on 2022/1/10.
//

#import "UIButton+ZKChain.h"

@implementation UIButton (ZKChain)

+ (UIButton * _Nonnull (^)(void))zk_allocInit{
    return ^{
         UIButton *v = [[UIButton alloc]init];
        return v;
    };
}

+ (UIButton * _Nonnull (^)(CGRect))zk_allocInitWithFrame{
    return ^(CGRect rect){
        UIButton * v = [[UIButton alloc]initWithFrame:rect];
        return v;
    };
}

- (UIButton * _Nonnull (^)(CGRect))zk_frame{
    return ^(CGRect rect){
        self.frame = rect;
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIColor * _Nonnull))zk_backgroundColor{
    return ^(UIColor *color){
        self.backgroundColor = color;
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIView * _Nonnull))zk_addToSuperView{
    return ^(UIView *view){
        [view addSubview:self];
        return self;
    };
}

- (UIButton * _Nonnull (^)(BOOL))zk_userInteractionEnabled{
    return ^(BOOL isUserInteractionEnabled){
        self.userInteractionEnabled = isUserInteractionEnabled;
        return self;
    };
}

- (UIButton * _Nonnull (^)(NSInteger))zk_tag{
    return ^(NSInteger tag){
        self.tag = tag;
        return self;
    };
}

- (UIButton * _Nonnull (^)(CGRect))zk_bounds;{
    return ^(CGRect rect){
        self.bounds = rect;
        return self;
    };
}

- (UIButton * _Nonnull (^)(CGPoint))zk_center{
    return ^(CGPoint point){
        self.center = point;
        return self;
    };
}

- (UIButton * _Nonnull (^)(CGFloat))zk_alpha{
    return ^(CGFloat value){
        self.alpha = value;
        return self;
    };
}

- (UIButton * _Nonnull (^)(BOOL))zk_hidden{
    return ^(BOOL isHidden){
        self.hidden = isHidden;
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIColor * _Nonnull))zk_tintColor{
    return ^(UIColor *col){
        self.tintColor = col;
        return self;
    };
}

#pragma mark UIControl 的
- (UIButton * _Nonnull (^)(BOOL))zk_selected{
    return ^(BOOL isSelected){
        self.selected = isSelected;
        return self;
    };
}

/// 设置按钮的highlighted
- (UIButton * _Nonnull (^)(BOOL))zk_highlighted{
    return ^(BOOL isHighlighted){
        self.highlighted = isHighlighted;
        return self;
    };
}

/// 设置按钮的highlighted
- (UIButton * _Nonnull (^)(BOOL))zk_enabled{
    return ^(BOOL isEnabled){
        self.enabled = isEnabled;
        return self;
    };
}

#pragma mark UIButton 的
/* UIButton 的*/
+ (UIButton * _Nonnull (^)(UIButtonType))zk_allocInitWithButtonType{
    return ^(UIButtonType btnType){
        UIButton * btn = [UIButton buttonWithType:btnType];
        return btn;
    };
}

- (UIButton * _Nonnull (^)(UIFont * _Nullable))zk_font{
    return ^(UIFont * font){
        self.titleLabel.font = font;
        return self;
    };
}


#pragma mark 对应UIButton 的一些方法

- (UIButton * _Nonnull (^)(NSString * _Nullable,UIControlState))zk_setTitleForState{
    return ^(NSString * title,UIControlState state){
        [self setTitle:title forState:state];
        return self;
    };
}

- (UIButton * _Nonnull (^)(UIColor * _Nullable, UIControlState))zk_setTitleColorForState{
    return ^(UIColor * color, UIControlState state){
        [self setTitleColor:color forState:state];
        return self;
    };
}

/// 设置前景图片
- (UIButton * _Nonnull (^)(UIImage * _Nullable,UIControlState))zk_setImageForState{
    return ^(UIImage * img,UIControlState state){
        [self setImage:img forState:state];
        return self;
    };
}

/// 设置背景图片
- (UIButton * _Nonnull (^)(UIImage * _Nullable,UIControlState))zk_setBackgroundImageForState{
    return ^(UIImage * img,UIControlState state){
        [self setBackgroundImage:img forState:state];
        return self;
    };
}

- (UIButton * _Nonnull (^)(NSAttributedString * _Nullable,UIControlState))zk_setAttributedTitleForState{
    return ^(NSAttributedString * attr ,UIControlState state){
        [self setAttributedTitle:attr forState:state];
        return self;
    };
}
@end
